import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int V = in.nextInt();
        int n = in.nextInt();
        int[] volum = new int[n];
        for (int i = 0; i < n; i++) {
            volum[i] = in.nextInt();
        }
        // 背包问题
        int[][] dp = new int[n+1][V+1];
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= V; j++) {
                dp[i][j] = dp[i-1][j];
                if (j >= volum[i-1]) {
                    dp[i][j] = Math.max(dp[i][j], dp[i-1][j-volum[i-1]]+volum[i-1]);
                }
            }
        }
        System.out.println(V-dp[n][V]);
    }

    // 空间优化
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int V = in.nextInt();
        int n = in.nextInt();
        int[] volum = new int[n];
        for (int i = 0; i < n; i++) {
            volum[i] = in.nextInt();
        }
        // 背包问题
        int[] dp = new int[V+1];
        for (int i = 1; i <= n; i++) {
            for (int j = V; j >= volum[i-1]; j--) {
                dp[j] = Math.max(dp[j], dp[j-volum[i-1]]+volum[i-1]);
            }
        }
        System.out.println(V-dp[V]);
    }
}
